﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;

public class TreeView
{
    [CompilerGenerated]
    private static Func<Node, IList<Node>> <>f__am$cache1;
    private Node rootNode;

    public TreeView()
    {
        Node node = new Node {
            expanded = true
        };
        this.rootNode = node;
    }

    public void AddPath(string value)
    {
        this.rootNode.Add(value);
    }

    public IEnumerable<Node> GetAllNodes()
    {
        return this.rootNode.GetDeepChildren();
    }

    public IEnumerable<Node> GetTreeNodes()
    {
        if (<>f__am$cache1 == null)
        {
            <>f__am$cache1 = n => !n.expanded ? null : n.children;
        }
        return this.Traverse<Node>(this.rootNode, <>f__am$cache1).Skip<Node>(1);
    }

    [DebuggerHidden]
    private IEnumerable<T> Traverse<T>(T item, Func<T, IList<T>> childSelector)
    {
        return new <Traverse>c__Iterator0<T> { item = item, childSelector = childSelector, <$>item = item, <$>childSelector = childSelector, $PC = -2 };
    }

    [CompilerGenerated]
    private sealed class <Traverse>c__Iterator0<T> : IDisposable, IEnumerator, IEnumerable, IEnumerable<T>, IEnumerator<T>
    {
        internal T $current;
        internal int $PC;
        internal Func<T, IList<T>> <$>childSelector;
        internal T <$>item;
        internal T <child>__4;
        internal IList<T> <children>__2;
        internal int <i>__3;
        internal T <next>__1;
        internal Stack<T> <stack>__0;
        internal Func<T, IList<T>> childSelector;
        internal T item;

        [DebuggerHidden]
        public void Dispose()
        {
            this.$PC = -1;
        }

        public bool MoveNext()
        {
            uint num = (uint) this.$PC;
            this.$PC = -1;
            switch (num)
            {
                case 0:
                    this.<stack>__0 = new Stack<T>();
                    this.<stack>__0.Push(this.item);
                    break;

                case 1:
                    this.<children>__2 = this.childSelector(this.<next>__1);
                    if (this.<children>__2 != null)
                    {
                        this.<i>__3 = this.<children>__2.Count - 1;
                        while (this.<i>__3 >= 0)
                        {
                            this.<child>__4 = this.<children>__2[this.<i>__3];
                            this.<stack>__0.Push(this.<child>__4);
                            this.<i>__3--;
                        }
                    }
                    break;

                default:
                    goto Label_00FE;
            }
            if (this.<stack>__0.Any<T>())
            {
                this.<next>__1 = this.<stack>__0.Pop();
                this.$current = this.<next>__1;
                this.$PC = 1;
                return true;
            }
            this.$PC = -1;
        Label_00FE:
            return false;
        }

        [DebuggerHidden]
        public void Reset()
        {
            throw new NotSupportedException();
        }

        [DebuggerHidden]
        IEnumerator<T> IEnumerable<T>.GetEnumerator()
        {
            if (Interlocked.CompareExchange(ref this.$PC, 0, -2) == -2)
            {
                return this;
            }
            return new TreeView.<Traverse>c__Iterator0<T> { item = this.<$>item, childSelector = this.<$>childSelector };
        }

        [DebuggerHidden]
        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.System.Collections.Generic.IEnumerable<T>.GetEnumerator();
        }

        T IEnumerator<T>.Current
        {
            [DebuggerHidden]
            get
            {
                return this.$current;
            }
        }

        object IEnumerator.Current
        {
            [DebuggerHidden]
            get
            {
                return this.$current;
            }
        }
    }

    public class Node
    {
        [CompilerGenerated]
        private static Func<char, bool> <>f__am$cache5;
        public List<TreeView.Node> children = new List<TreeView.Node>();
        public bool expanded;
        public string name = string.Empty;
        public TreeView.Node parent;
        public string path = string.Empty;

        public TreeView.Node Add(string path)
        {
            <Add>c__AnonStorey33 storey = new <Add>c__AnonStorey33();
            if (string.IsNullOrEmpty(path))
            {
                return null;
            }
            storey.childName = path;
            string str = string.Empty;
            char[] separator = new char[] { '/' };
            string[] source = path.Split(separator);
            if (source.Length >= 2)
            {
                storey.childName = source[0];
                str = string.Join("/", source.Skip<string>(1).ToArray<string>());
            }
            TreeView.Node item = this.children.Find(new Predicate<TreeView.Node>(storey.<>m__9));
            if (item == null)
            {
                item = new TreeView.Node {
                    parent = this,
                    name = storey.childName,
                    path = string.IsNullOrEmpty(this.path) ? storey.childName : (this.path + "/" + storey.childName)
                };
                this.children.Add(item);
            }
            item.Add(str);
            return item;
        }

        [DebuggerHidden]
        public IEnumerable<TreeView.Node> GetDeepChildren()
        {
            return new <GetDeepChildren>c__Iterator1 { <>f__this = this, $PC = -2 };
        }

        public int indentLevel
        {
            get
            {
                if (<>f__am$cache5 == null)
                {
                    <>f__am$cache5 = x => x == '/';
                }
                return this.path.Count<char>(<>f__am$cache5);
            }
        }

        [CompilerGenerated]
        private sealed class <Add>c__AnonStorey33
        {
            internal string childName;

            internal bool <>m__9(TreeView.Node x)
            {
                return (x.name == this.childName);
            }
        }

        [CompilerGenerated]
        private sealed class <GetDeepChildren>c__Iterator1 : IDisposable, IEnumerable<TreeView.Node>, IEnumerator<TreeView.Node>, IEnumerator, IEnumerable
        {
            internal TreeView.Node $current;
            internal int $PC;
            internal List<TreeView.Node>.Enumerator <$s_7>__0;
            internal IEnumerator<TreeView.Node> <$s_8>__2;
            internal TreeView.Node <>f__this;
            internal TreeView.Node <child>__1;
            internal TreeView.Node <deepChild>__3;

            [DebuggerHidden]
            public void Dispose()
            {
                uint num = (uint) this.$PC;
                this.$PC = -1;
                switch (num)
                {
                    case 1:
                    case 2:
                        try
                        {
                            switch (num)
                            {
                                case 2:
                                    try
                                    {
                                    }
                                    finally
                                    {
                                        if (this.<$s_8>__2 == null)
                                        {
                                        }
                                        this.<$s_8>__2.Dispose();
                                    }
                                    return;
                            }
                        }
                        finally
                        {
                            this.<$s_7>__0.Dispose();
                        }
                        break;
                }
            }

            public bool MoveNext()
            {
                uint num = (uint) this.$PC;
                this.$PC = -1;
                bool flag = false;
                switch (num)
                {
                    case 0:
                        this.<$s_7>__0 = this.<>f__this.children.GetEnumerator();
                        num = 0xfffffffd;
                        break;

                    case 1:
                    case 2:
                        break;

                    default:
                        goto Label_0134;
                }
                try
                {
                    switch (num)
                    {
                        case 1:
                            this.<$s_8>__2 = this.<child>__1.GetDeepChildren().GetEnumerator();
                            num = 0xfffffffd;
                            goto Label_0099;

                        case 2:
                            goto Label_0099;
                    }
                    while (this.<$s_7>__0.MoveNext())
                    {
                        this.<child>__1 = this.<$s_7>__0.Current;
                        this.$current = this.<child>__1;
                        this.$PC = 1;
                        flag = true;
                        goto Label_0136;
                    Label_0099:
                        try
                        {
                            while (this.<$s_8>__2.MoveNext())
                            {
                                this.<deepChild>__3 = this.<$s_8>__2.Current;
                                this.$current = this.<deepChild>__3;
                                this.$PC = 2;
                                flag = true;
                                goto Label_0136;
                            }
                        }
                        finally
                        {
                            if (!flag)
                            {
                            }
                            if (this.<$s_8>__2 == null)
                            {
                            }
                            this.<$s_8>__2.Dispose();
                        }
                    }
                }
                finally
                {
                    if (!flag)
                    {
                    }
                    this.<$s_7>__0.Dispose();
                }
                this.$PC = -1;
            Label_0134:
                return false;
            Label_0136:
                return true;
            }

            [DebuggerHidden]
            public void Reset()
            {
                throw new NotSupportedException();
            }

            [DebuggerHidden]
            IEnumerator<TreeView.Node> IEnumerable<TreeView.Node>.GetEnumerator()
            {
                if (Interlocked.CompareExchange(ref this.$PC, 0, -2) == -2)
                {
                    return this;
                }
                return new TreeView.Node.<GetDeepChildren>c__Iterator1 { <>f__this = this.<>f__this };
            }

            [DebuggerHidden]
            IEnumerator IEnumerable.GetEnumerator()
            {
                return this.System.Collections.Generic.IEnumerable<TreeView.Node>.GetEnumerator();
            }

            TreeView.Node IEnumerator<TreeView.Node>.Current
            {
                [DebuggerHidden]
                get
                {
                    return this.$current;
                }
            }

            object IEnumerator.Current
            {
                [DebuggerHidden]
                get
                {
                    return this.$current;
                }
            }
        }
    }
}

